package com.planet.stockanalysis.utils;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SingleApplicationContext {
	
	private static SingleApplicationContext instance;
	private static ApplicationContext applicationContext;
	
	public static SingleApplicationContext getInstance(){
		if(instance == null){
			synchronized(SingleApplicationContext.class) {
				if(null == instance) {
					instance = new SingleApplicationContext();
					applicationContext = new ClassPathXmlApplicationContext("spring-cfg.xml");
				}
			}
		}
		
		return instance;
	}
	
	public Object getBean(String beanName) {
		
		if(applicationContext == null) {
			applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
		}
		
		return applicationContext.getBean(beanName);
	}
}
